package com.example.testapp.data.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import java.time.LocalDateTime

/**
 * 账单图片表
 */
@Entity(
    tableName = "balance_image",
    foreignKeys = [
        ForeignKey(
            entity = Balance::class,
            parentColumns = ["id"],
            childColumns = ["balance_id"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [
        Index(name = "idx_balance_image_balance_id", value = ["balance_id"]),
        Index(name = "idx_balance_image_is_processed", value = ["is_processed"]),
        Index(name = "idx_balance_image_del_flag", value = ["del_flag"])
    ]
)
class BalanceImage : BaseEntity() {

    /**
     * 关联账单ID
     */
    @JvmField
    @ColumnInfo(name = "balance_id")
    var balanceId: Long? = null

    /**
     * 图片存储路径
     */
    @JvmField
    @ColumnInfo(name = "image_path")
    var imagePath: String? = null

    /**
     * 是否已处理
     */
    @JvmField
    @ColumnInfo(name = "is_processed")
    var processed: Boolean? = null

    /**
     * 排序顺序
     */
    @JvmField
    @ColumnInfo(name = "sort_order")
    var sortOrder: Int? = null

    /**
     * 识别状态（1-未识别，2-识别中，3-识别成功，4-识别失败）
     */
    @JvmField
    @ColumnInfo(name = "recognition_status")
    var recognitionStatus: Int? = null

    // Getter和Setter方法，用于Java代码兼容性
    fun getBalanceId(): Long? = balanceId
    fun setBalanceId(balanceId: Long) { this.balanceId = balanceId }

    fun getImagePath(): String? = imagePath
    fun setImagePath(path: String?) { this.imagePath = path }

    fun isProcessed(): Boolean? = processed
    fun getIsProcessed(): Boolean? = processed
    fun setIsProcessed(processed: Boolean?) { this.processed = processed }

    fun getSortOrder(): Int? = sortOrder
    fun setSortOrder(sortOrder: Int?) { this.sortOrder = sortOrder }

    fun getRecognitionStatus(): Int? = recognitionStatus
    fun setRecognitionStatus(recognitionStatus: Int?) { this.recognitionStatus = recognitionStatus }

    // 从BaseEntity继承的字段的Getter和Setter
    fun getId(): Long = id
    fun setId(id: Long) { this.id = id }

    fun getCreateDate(): LocalDateTime? = createDate
    fun setCreateDate(createDate: LocalDateTime?) { this.createDate = createDate }

    fun getUpdateDate(): LocalDateTime? = updateDate
    fun setUpdateDate(updateDate: LocalDateTime?) { this.updateDate = updateDate }

    fun getDelAt(): LocalDateTime? = delAt
    fun setDelAt(delAt: LocalDateTime?) { this.delAt = delAt }

    fun getDelFlag(): Int? = delFlag
    fun setDelFlag(delFlag: Int?) { this.delFlag = delFlag }
    fun setDelFlag(delFlag: Byte) { this.delFlag = delFlag.toInt() }

    companion object {
        /**
         * 识别状态：未识别
         */
        const val RECOGNITION_STATUS_PENDING = 1
        
        /**
         * 识别状态：识别中
         */
        const val RECOGNITION_STATUS_PROCESSING = 2
        
        /**
         * 识别状态：识别成功
         */
        const val RECOGNITION_STATUS_SUCCESS = 3
        
        /**
         * 识别状态：识别失败
         */
        const val RECOGNITION_STATUS_FAILED = 4
    }
} 